package me.pearjelly.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.hibernate.annotations.GenericGenerator;

@Entity
public class Crawler {
	public static final Crawler defaultInstance() {
		Crawler crawler = new Crawler();
		crawler.setDomain("http://yy.mxlady.com/");
		crawler.setDepth(3);
		crawler.setSeeds("http://yy.mxlady.com/jiaodian/2010-08/showgirl2010.html");
		crawler.setFilterReg(".*(\\.(css|js|mid|mp2|mp3|mp4|wav|avi|mov|mpeg|ram|m4v|pdf|rm|smil|wmv|swf|wma|zip|rar|gz|bmp|gif|png|tiff?))$");
		crawler.setEndPageReg(".*(\\.s?html?)$");
		crawler.setImgReg(".*(\\.(jpe?g))$");
		crawler.setWorkDir("moxiu");
		crawler.setMinWidth(200);
		crawler.setMinHeight(150);
		crawler.setStatus(0);
		return crawler;
	}

	private int id;
	private String name;
	private String domain;
	private String seeds;
	private Set<Category> categories = new HashSet<Category>();
	private Set<Selector> selectors = new HashSet<Selector>();
	private int depth;
	private String filterReg;
	private String endPageReg;
	private String imgReg;
	private String urlResetReg;
	private String groupPageReg;
	private String workDir;
	private int minWidth;
	private int minHeight;
	private String description;
	private int status;

	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getSeeds() {
		return seeds;
	}

	public void setSeeds(String seeds) {
		this.seeds = seeds;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "category_crawler", joinColumns = { @JoinColumn(name = "crawler_id") }, inverseJoinColumns = { @JoinColumn(name = "category_id") })
	public Set<Category> getCategories() {
		return categories;
	}

	public void setCategories(Set<Category> categories) {
		this.categories = categories;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
	@JoinColumn(name = "crawler_id")
	public Set<Selector> getSelectors() {
		return selectors;
	}

	public void setSelectors(Set<Selector> selectors) {
		this.selectors = selectors;
	}

	public int getDepth() {
		return depth;
	}

	public void setDepth(int depth) {
		this.depth = depth;
	}

	public String getFilterReg() {
		return filterReg;
	}

	public void setFilterReg(String filterReg) {
		this.filterReg = filterReg;
	}

	public String getEndPageReg() {
		return endPageReg;
	}

	public void setEndPageReg(String endPageReg) {
		this.endPageReg = endPageReg;
	}

	public String getImgReg() {
		return imgReg;
	}

	public void setImgReg(String imgReg) {
		this.imgReg = imgReg;
	}

	public String getUrlResetReg() {
		return urlResetReg;
	}

	public void setUrlResetReg(String urlResetReg) {
		this.urlResetReg = urlResetReg;
	}
	public String getGroupPageReg() {
		return groupPageReg;
	}
	public void setGroupPageReg(String groupPageReg) {
		this.groupPageReg = groupPageReg;
	}
	public String getWorkDir() {
		return workDir;
	}

	public void setWorkDir(String workDir) {
		this.workDir = workDir;
	}

	public int getMinWidth() {
		return minWidth;
	}

	public void setMinWidth(int minWidth) {
		this.minWidth = minWidth;
	}

	public int getMinHeight() {
		return minHeight;
	}

	public void setMinHeight(int minHeight) {
		this.minHeight = minHeight;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

}
